package com.shao.controller;


import com.shao.bean.admin;
import com.shao.bean.loginBean;
import com.shao.bean.teacher;
import com.shao.common.R;
import com.shao.service.admService;
import com.shao.service.stuService;
import com.shao.service.teaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: com.song shao
 * @date: 2022/2/25
 * @time: 18:31
 * @version: 1.0
 */
@SuppressWarnings("all")
@RestController
public class LoginController {


    @Autowired
    private stuService stu;

    @Autowired
    private admService adm;

    @Autowired
    private teaService tea;

    /**
     * 所有用户的登录入口
     *
     * @param stu
     * @return
     */
    @PostMapping("/login")
    public R loginReginfo(@RequestBody loginBean loginPeopel) {
        int states = loginPeopel.getStates();  // 判断当前是那种用户 0 =>学生 1=> 教师 3 => 管理员;
        if (states == 0) {
            // 调用学生的service
            return stu.loginVerify(loginPeopel);
        }
        if (states == 1) {
            // 调用教师的sercie
            teacher teacher = new teacher();
            teacher.setTea_username(loginPeopel.getName());
            teacher.setTea_pwd(loginPeopel.getPwd());
            return tea.loginVerify(teacher);
        }
        if (states == 3) {
            // 调用管理员的service
            admin am = new admin();
            am.setAdm_username(loginPeopel.getName());
            am.setAdm_password(loginPeopel.getPwd());
            return adm.loginVerify(am);
        }
        return R.error("你的网络有问题，请稍后重试！");
    }
}
